#ifndef UTILS_H
#define	UTILS_H

#include <iostream>
#include "../log/LoggerManager.h"
namespace zipUtils
{
    /**
    * Calculates the size of the file in bytes.
    * 
    * @param file File.
    * 
    * @return Return the size of the file in bytes
    */
    long calculateSize(FILE* file);

    /**
    * Copy the content of the file in bytes to a buffer
    * 
    * @param file File
    * @param buffer Buffer where the content of file will be copied
    * @param size Size of the buffer the size must to be increased by one for add the end of the buffer ('\0')
    */
    void getBytes(FILE* file, char* buffer, size_t size);

    /**
    * Calculates the CRC-32 of a file.
    * 
    * @param file File
    * 
    * @return Return the CRC-32 of the file
    */
    long getCRC32(FILE* file);

    /**
    * Identify if the given path is a directory
    * 
    * @param path of the file to be evaluated
    * @return bool true if it's a directory false if it doesn't
    */
    bool isDirectory(char *path);
    /**
    * Identify if the given path is a file
    * 
    * @param path  of the file to be evaluated
    * @return true if it's a file false if it doesn't
    */
    bool isFile(char *path);

    /**
    * Copy the toCopy value to the buffer since a position
    * 
    * @param buffer Buffer when the value will be copied
    * @param toCopy Value that will be added in the buffer
    * @param since Position in the buffer where the value will be copied
    * @param size Size of the value
    */
    void copy(char*& buffer, const void* toCopy, size_t since, const size_t size);

    /**
    * Concatenate in a buffer the char array toCopy
    * 
    * @param buffer Buffer
    * @param toCopy Char array to will be added in the buffer
    * @param since Position in the buffer where the char array will be copied
    * @param size Size of the char array
    */
    void conCat(char*& buffer, const char* toCopy, size_t since, const size_t size);
    
    /**
     * Parse a date to short, following the MS DOS standard.
     * 
     * @param date char array when the date will be recovered
     * 
     * @return The date stored in a short
     */
    short parseDateToShort(tm* date);
    
    /**
     * Parse a time to short, following the MS DOS standard.
     * 
     * @param date char array when the time will be recovered
     * 
     * @return The time stored in a short.
     */
    short parseTimeToShort(tm* date);
    
    /**
     * Recover the last modification date and time of a file
     * 
     * @param path Path of the file
     * 
     * @return Return the last modification date and time;
     */
    tm* getLastModificationTimeAndDate(char* path);
/**
 * Verify if a file it's broken or corrupt
 * 
 * @param file file to verify data
 * @return true is it's broken false if it doesn't
 */    
    bool isCorruptFile(char* file);
    
    /**
     * Get the position of the last occurence of the find.
     * 
     * @param str String
     * @param find Character 
     * 
     * @return The position of the last occurence, if does not find return -1
     */
    int lastIndexOf(const char* str, char find);
}
#endif	/* UTILS_H */
